import { setXsrftoken } from '@/utils/auth'
import { cache } from '@/utils/index'
import Http from '@/utils/http'
import api from '@/api/index'

/**
 * 后台系统配置信息
 */
export function init() {
  return Http.get(api.admin_init).then(resp => {
    // console.log('init resp', resp)
    setXsrftoken(resp.data.xsrf_token)
    var data = resp.data
    delete data.xsrf_token
    cache('sys_cfg', data)
  }).catch( err => {
    console.log(err)
  })
}

export function login(params) {
  return Http.post(api.admin_login, params)
}

export function info(token) {
  return Http.get(api.admin_info, { token })
}

export function logout() {
  return Http.post(api.admin_logout)
}

// 获取图形验证码
export function getCaptcha() {
  return Http.get(api.Captcha, {t: new Date().getTime()})
}
